import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-04-16
 * Time: 19:35
 */

class Student {

}

class IntCom implements Comparator<Integer> {
    public int compare(Integer o1,Integer o2) {
        return o2.compareTo(o1);
    }
}


public class Test {
    public static void main(String[] args) {
        int[] array = {27,15,19,18,28,34,65,49,25,37 };
        TestHeap testHeap = new TestHeap();
        testHeap.init(array);
        testHeap.createHeap();
        testHeap.heapSort();
    }
    public int[] smallestK(int[] arr, int k) {
        PriorityQueue<Integer> priorityqueue1 = new PriorityQueue<>();
        for(int i = 0; i < arr.length; i++) {
            priorityqueue1.offer(arr[i]);
        }
        int[] tmp = new int[k];
        for(int j = 0; j < k; j++) {
            int val = priorityqueue1.poll();
            tmp[j] = val;
        }
        return tmp;
    }

    public int[] smallestK1(int[] arr, int k) {
        int[] tmp = new int[k];
        if(k == 0) {
            return tmp;
        }
        PriorityQueue<Integer> priorityqueue1 = new PriorityQueue<>(new IntCom());
        for(int i = 0; i < k; i++) {
            priorityqueue1.offer(arr[i]);
        }
        for(int i = k; i < arr.length; i++) {
            int val = priorityqueue1.peek();
            if(val > arr[i]) {
                priorityqueue1.poll();
                priorityqueue1.offer(arr[i]);
            }
        }
        for(int i = 0; i < k; i++) {
            tmp[i] = priorityqueue1.poll();
        }
        return tmp;

    }



    public static void main4(String[] args) {
        PriorityQueue<Integer> priorityqueue1 = new PriorityQueue<>(new IntCom());
        priorityqueue1.offer(12);
        priorityqueue1.offer(5);
        priorityqueue1.offer(47);
        System.out.println(priorityqueue1.poll());
        System.out.println(priorityqueue1.poll());
    }

    public static void main3(String[] args) {

        ArrayList<Integer> List = new ArrayList<>();PriorityQueue<Student> priorityqueue1 = new PriorityQueue<>();
        priorityqueue1.offer(new Student());
        priorityqueue1.offer(new Student());
        priorityqueue1.offer(null);
        List.add(1);
        List.add(2);
        List.add(3);
        PriorityQueue<Integer> priorityqueue2 = new PriorityQueue<>(List);
        System.out.println(priorityqueue2.poll());
        System.out.println(priorityqueue2.poll());
    }


    public static void main2(String[] args) {
        PriorityQueue<Integer> priorityqueue = new PriorityQueue<>();
        priorityqueue.offer(12);
        priorityqueue.offer(5);
        priorityqueue.offer(48);
        System.out.println(priorityqueue.poll());
        System.out.println(priorityqueue.poll());
    }


    public static void main1(String[] args) {
        int[] array = {27,15,19,18,28,34,65,49,25,37 };
        TestHeap testHeap = new TestHeap();
        testHeap.init(array);
        testHeap.createHeap();
        /*testHeap.offer(80);
        testHeap.poll();*/
    }
}
